package com.example.yiqiuser.service.impl;


import com.example.yiqiuser.dao.TScenicStrategyDao;
import com.example.yiqiuser.entity.TScenicStrategy;
import com.example.yiqiuser.service.TScenicStrategyService;
import com.example.yiqiuser.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：周文达
 * @date ：Created in 2023/3/31 10:48
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class TScenicStrategyServiceImpl implements TScenicStrategyService {
    @Resource
    private TScenicStrategyDao tScenicStrategyDao;

    @Override
    public PageInfo<TScenicStrategy> queryByParam(Page<TScenicStrategy> page) {
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        return new PageInfo<>(tScenicStrategyDao.queryByParam(page.getData()));
    }

    @Override
    public TScenicStrategy queryById(int scenicId) {
        List<TScenicStrategy> tScenicStrategies = tScenicStrategyDao.queryById(scenicId);
        if (tScenicStrategies != null && tScenicStrategies.size() > 0) {
            return tScenicStrategies.get(0);
        }
        return null;
    }

    @Override
    public List<TScenicStrategy> queryAll() {
        TScenicStrategy tScenicStrategy = new TScenicStrategy();

        return tScenicStrategyDao.queryByParam(tScenicStrategy);
    }

    @Override
    public int add(TScenicStrategy tScenicStrategy) {
        return tScenicStrategyDao.add(tScenicStrategy);
    }

    @Override
    public int deleteById(int scenicId) {
        return tScenicStrategyDao.deleteById(scenicId);
    }

    @Override
    public int update(TScenicStrategy tScenicStrategy) {
        try {
            tScenicStrategyDao.update(tScenicStrategy);
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
}